package com.alfayun.fiscalriskanalysis.report;

import java.time.LocalDate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.springframework.format.annotation.DateTimeFormat;

import com.alfayun.fiscalriskanalysis.enterprise.Enterprise;

@Entity
@Table(name = "report_group")
public class ReportGroup {

	@Column(name = "report_group_id", updatable = false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Id
	private Integer id;
	@Enumerated(EnumType.STRING)
	public ReportPeriod period;// 报表期限(年报、季度...)
	@DateTimeFormat(pattern = "yyyy/MM/dd")
	public LocalDate startDate;
	@DateTimeFormat(pattern = "yyyy/MM/dd")
	public LocalDate endDate;
	@Enumerated(EnumType.STRING) // 完成的状态：初始化，未完成，已完成
	public CompleteStatus completeStatus;
	@OneToOne
	@JoinColumn(name = "enterprise_id")
	public Enterprise enterprise;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public ReportPeriod getPeriod() {
		return period;
	}

	public void setPeriod(ReportPeriod period) {
		this.period = period;
	}

	public LocalDate getStartDate() {
		return startDate;
	}

	public void setStartDate(LocalDate startDate) {
		this.startDate = startDate;
	}

	public LocalDate getEndDate() {
		return endDate;
	}

	public void setEndDate(LocalDate endDate) {
		this.endDate = endDate;
	}

	public CompleteStatus getCompleteStatus() {
		return completeStatus;
	}

	public void setCompleteStatus(CompleteStatus completeStatus) {
		this.completeStatus = completeStatus;
	}

	public Enterprise getEnterprise() {
		return enterprise;
	}

	public void setEnterprise(Enterprise enterprise) {
		this.enterprise = enterprise;
	}

	public static ReportGroup newReportGroup(ReportGroupRepository repository, ReportGroup reportGroup) {
		reportGroup.id = 0;

		return repository.save(reportGroup);
	}

}
